home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.07 Jul 87 / bit map source / dragsample1.p < prev    next >
Encoding:
Text File  |  1987-04-24  |  2.4 KB  |  99 lines  |  [TEXT/MPS ]

  1. program DragExample1;
  2. {$D+}    {put in debug names}
  3. {$R+}    {range checking on}
  4. {$OV+} {overflow checking on}
  5. {$N+}    {pass routine names to linker, so they're not anonymous}
  6. USES {$LOAD pinterfaces.dump}        
  7.         MemTypes,QuickDraw,OsIntf,PasLibIntf,ToolIntf,
  8.         PackIntf,IntEnv,CursorCtl,
  9.         {$LOAD}
  10.         {$U UDrag.p}    DragManager;
  11.  
  12. var
  13.     myPic : PicHandle;
  14.     myRect : Rect;
  15.     wPort: GrafPtr;
  16.     whichPict,
  17.     x,y,xinc,yinc : integer;
  18.     xyPt, lastXYPt : point;
  19.     myEventRecord : EventRecord;
  20.     lastCount : longint;
  21.     
  22.     myDragStuff : DragHandle;
  23.  
  24. procedure DragItAround;
  25. const 
  26.     CapsLockBit = 10;
  27. begin
  28. SetPt( lastXYPt, -1, -1 );
  29. repeat
  30.     GetMouse(xyPt);
  31. {if the movement is far enough, the next line of code (commented out)
  32.  can be used to make the image persist long enough that it doesn't appear
  33.  ghostly.  On the other hand, if the movement is very small, the image
  34.  generally looks nice and solid and does not benefit from delays.}
  35.     {if TickCount >= lastCount + 2 then}
  36.     if not EqualPt( xyPt, lastXYPt) then 
  37.     begin
  38.     {if CapsLockKey, don't show the shadow, else show it}
  39.         if EventAvail(0, myEventRecord) then {twiddle thumbs};
  40.         if BTST(myEventRecord.modifiers, CapsLockBit) 
  41.         then with shadowStuff do 
  42.             begin dx := 0; dy := 0;  visible := false; end 
  43.         else with shadowStuff do
  44.         begin
  45.             dx := xyPt.h div 8 - 32;
  46.             dy := xyPt.v div 8 - 20;
  47.             visible := true;
  48.         end;
  49.  
  50.         DragItTo( myDragStuff, xyPt, true );
  51.  
  52.         lastXYPt := xyPt;
  53.         lastCount := TickCount;
  54.     end;
  55.     {allow for FKEY access and give DAs and such time}
  56.     if GetNextEvent( keyDownMask, myEventRecord ) then {do nothing};
  57.     SystemTask;
  58. until button;
  59. repeat until not button;
  60. end; {dragitaround}
  61.  
  62. begin{main}
  63.     InitGraf(@thePort);
  64.     
  65. {standalones need to init windows, but tools shouldn't}
  66.     if IEStandalone then InitWindows;
  67.     
  68.     GetWMgrPort( wPort );
  69.     SetPort( wPort );
  70.     ClipRect( screenBits.bounds );
  71.     InitCursor;
  72.     HideCursor;    
  73.     
  74.     if not InitDrag( nil ) then exit( DragExample1 );
  75.     
  76. for whichPict := 1 to CountResources('PICT') do
  77. begin
  78.     myPic := PicHandle(GetIndResource('PICT', whichPict));
  79.     if myPic = nil then 
  80.         begin SysBeep(1); exit(DragExample1); end;
  81.         {change up the default shadow stuff}
  82.         with shadowStuff do
  83.         begin
  84.                 thePattern := gray;
  85.                 copyMode := SrcOr;
  86.         end;
  87.  
  88.     if not NewDraggable( myPic, nil, nil, myDragStuff )
  89.         then exit(DragExample1);
  90.     DragItAround;    
  91.     DisposeDraggable( myDragStuff );
  92.     ReleaseResource( Handle( myPic ));
  93. end;
  94.  
  95. CloseDrag( true );
  96. FlushEvents( everyEvent, 0 );
  97.  
  98. end.
  99.